﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Net;
using System.Collections;
using System.Xml;
using System.Linq;
//using System.Xml.Linq;

using CommonUtils;
using TDAL = EzDAL.Auto2;
using TDALUtils = EzDAL.Utils;
using TConst = TERP.Constants;
using TUtils = TERP.Utils;
using TError = TERP.Errors;


namespace TERP.BizHTC
{
	public partial class BizHTC
	{
		#region // Private Utils:
		#endregion

		#region // Public Sequence:
		public DataSet SequenceGetForDMS(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strSequenceType
			, string strParam1
			, string strParam2
			, string strParam3
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "SequenceGetForDMS";
			string strErrorCodeDefault = TError.ErrHTC.SequenceGetForDMS;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strSequenceType", strSequenceType
					, "strParam1", strParam1
					, "strParam2", strParam2
					, "strParam3", strParam3
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Check:
				// Refine:
				strSequenceType = strSequenceType.ToUpper();
				strParam1 = strParam1.ToUpper();
				strParam2 = strParam2.ToUpper();
				strParam3 = strParam3.ToUpper();

				// Get and Check Map:
				Hashtable htMap = new Hashtable();
				htMap.Add(TConst.SequenceTypeDMS.Id, new string[] { "", "", "0"});
				htMap.Add(TConst.SequenceTypeDMS.SalesOrderPlan, new string[] { "Seq_DMS_SO", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.SalesOrderUnplan, new string[] { "Seq_DMS_SO", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.PurchaseOrder, new string[] { "Seq_DMS_PO", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.POCommand, new string[] { "Seq_DMS_PO", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.Car, new string[] { "Seq_DMS_Car", "{0}{1}{2:0000}{3}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.PackingList, new string[] { "Seq_DMS_PL", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.Payment, new string[] { "Seq_DMS_PM", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.PaymentAdjust, new string[] { "Seq_DMS_PM", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.DeliveryOrder, new string[] { "Seq_DMS_CarReq", "{0}{1}{2:0000}", "10000" });
				htMap.Add(TConst.SequenceTypeDMS.CarDocumentsRequest, new string[] { "Seq_DMS_CarReq", "{0}{1}{2:0000}", "10000" });
				if (!htMap.ContainsKey(strSequenceType))
				{
					throw CMyException.Raise(
						TError.ErrHTC.SequenceGetForDMS_InvalidSequenceType // strErrorCode
						, null // excInner
						, alParamsCoupleError.ToArray() // arrobjParamsCouple
						);
				}
				string[] arrstrMap = (string[])htMap[strSequenceType];
				string strTableName = arrstrMap[0];
				string strFormat = arrstrMap[1];
				string strSeqThreshold = arrstrMap[2];
				#endregion

				#region // SequenceGet:
				string strResult = "";
				if (StringUtils.StringEqual(strSequenceType, TConst.SequenceTypeDMS.Id))
				{
					strResult = myCommon_GetNewId("Seq_Id", "");
				}
				else
				{
					long nSeq = myUtils_GetSeqRaw(strTableName);
					strResult = string.Format(
						strFormat
						, DateTime.Now.ToString("yyMM") // {0}
						, strSequenceType // {1}
						, nSeq % Convert.ToInt32(strSeqThreshold) // {2}
						, strParam1 // {3}
						, strParam2 // {4}
						, strParam3 // {5}
						);
				}
				CMyDataSet.SetRemark(ref mdsFinal, strResult);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		#endregion

		#region // Public MasterData:
		public DataSet MstDataGetCarPrice(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strSpecCodeList
			, string strSpecCodePattern
			, string strEffectiveDateFrom
			, string strEffectiveDateTo
			, string strFlagActiveListForCarPrice
			, string strModelCodeList
			, string strStandardCodeList
			, string strAdvancedCodeList
			, string strFlagActiveListForModel
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "MstDataGetCarPrice";
			string strErrorCodeDefault = TError.ErrHTC.MstDataGetCarPrice;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strSpecCodeList", strSpecCodeList
					, "strSpecCodePattern", strSpecCodePattern
					, "strEffectiveDateFrom", strEffectiveDateFrom
					, "strEffectiveDateTo", strEffectiveDateTo
					, "strFlagActiveListForCarPrice", strFlagActiveListForCarPrice
					, "strModelCodeList", strModelCodeList
					, "strStandardCodeList", strStandardCodeList
					, "strAdvancedCodeList", strAdvancedCodeList
					, "strFlagActiveListForModel", strFlagActiveListForModel
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.SpecCode
							, t.EffectiveDate
							, t.UnitPrice
							, t.FlagActive
							, mmao.ModelCode
							, mmao.StandardCode
							, mmao.AdvancedCode
							, mmao.AdvDescription
							, mmso.StdDescription
							, (mmao.AdvDescription + ', ' + mmso.StdDescription) Description
							, mm.ModelProductionCode
							, mm.ModelName
							, mm.FlagActive MMFlagActive
						from Mst_CarPrice t with (nolock)
							inner join Mst_ModelAdvancedOption mmao with (nolock)
								on t.SpecCode = mmao.SpecCode
							inner join Mst_ModelStandardOption mmso with (nolock)
								on mmao.ModelCode = mmso.ModelCode and mmao.StandardCode = mmso.StandardCode
							inner join Mst_Model mm with (nolock)
								on mmao.ModelCode = mm.ModelCode
						where (1=1)
							zzzzClauseWhereSpecCodeList
							zzzzClauseWhereSpecCodePattern
							zzzzClauseWhereEffectiveDateFrom
							zzzzClauseWhereEffectiveDateTo
							zzzzClauseWhereFlagActiveListForCarPrice
							zzzzClauseWhereModelCodeList
							zzzzClauseWhereStandardCodeList
							zzzzClauseWhereAdvancedCodeList
							zzzzClauseWhereFlagActiveListForModel
						;
					";
				string zzzzClauseWhereSpecCodeList = SqlUtils.BuildClauseConditionList("and", "t.SpecCode", strSpecCodeList, "|");
				string zzzzClauseWhereSpecCodePattern = SqlUtils.BuildClauseConditionSingle("and", "t.SpecCode", "like", "@strSpecCodePattern", strSpecCodePattern, ref alParamsCoupleSql);
				string zzzzClauseWhereEffectiveDateFrom = SqlUtils.BuildClauseConditionSingle("and", "t.EffectiveDate", ">=", "@strEffectiveDateFrom", strEffectiveDateFrom, ref alParamsCoupleSql);
				string zzzzClauseWhereEffectiveDateTo = SqlUtils.BuildClauseConditionSingle("and", "t.EffectiveDate", "<=", "@strEffectiveDateTo", strEffectiveDateTo, ref alParamsCoupleSql);
				string zzzzClauseWhereFlagActiveListForCarPrice = SqlUtils.BuildClauseConditionList("and", "t.FlagActive", strFlagActiveListForCarPrice, "|");
				string zzzzClauseWhereModelCodeList = SqlUtils.BuildClauseConditionList("and", "t.ModelCode", strModelCodeList, "|");
				string zzzzClauseWhereStandardCodeList = SqlUtils.BuildClauseConditionList("and", "t.StandardCode", strStandardCodeList, "|");
				string zzzzClauseWhereAdvancedCodeList = SqlUtils.BuildClauseConditionList("and", "t.AdvancedCode", strAdvancedCodeList, "|");
				string zzzzClauseWhereFlagActiveListForModel = SqlUtils.BuildClauseConditionList("and", "mm.FlagActive", strFlagActiveListForModel, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereSpecCodeList", zzzzClauseWhereSpecCodeList
					, "zzzzClauseWhereSpecCodePattern", zzzzClauseWhereSpecCodePattern
					, "zzzzClauseWhereEffectiveDateFrom", zzzzClauseWhereEffectiveDateFrom
					, "zzzzClauseWhereEffectiveDateTo", zzzzClauseWhereEffectiveDateTo
					, "zzzzClauseWhereFlagActiveListForCarPrice", zzzzClauseWhereFlagActiveListForCarPrice
					, "zzzzClauseWhereModelCodeList", zzzzClauseWhereModelCodeList
					, "zzzzClauseWhereStandardCodeList", zzzzClauseWhereStandardCodeList
					, "zzzzClauseWhereAdvancedCodeList", zzzzClauseWhereAdvancedCodeList
					, "zzzzClauseWhereFlagActiveListForModel", zzzzClauseWhereFlagActiveListForModel
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _db.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Mst_CarPrice";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet MstDataGetModelAdvancedOption(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strSpecCodeList
			, string strSpecCodePattern
			, string strModelCodeList
			, string strStandardCodeList
			, string strAdvancedCodeList
			, string strFlagActiveListForModel
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "MstDataGetModelAdvancedOption";
			string strErrorCodeDefault = TError.ErrHTC.MstDataGetModelAdvancedOption;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strSpecCodeList", strSpecCodeList
					, "strSpecCodePattern", strSpecCodePattern
					, "strModelCodeList", strModelCodeList
					, "strStandardCodeList", strStandardCodeList
					, "strAdvancedCodeList", strAdvancedCodeList
					, "strFlagActiveListForModel", strFlagActiveListForModel
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.ModelCode
							, t.StandardCode
							, t.AdvancedCode
							, t.SpecCode
							, t.AdvDecription
							, mmso.StdDescription
							, (t.AdvDescription + ', ' + mmso.StdDescription) Description
							, mm.ModelProductionCode
							, mm.ModelName
							, mm.FlagActive MMFlagActive
						from Mst_ModelAdvanedOption t with (nolock)
							inner join Mst_ModelStandardOption mmso with (nolock)
								on t.ModelCode = mmso.ModelCode and t.StandardCode = mmso.StandardCode
							inner join Mst_Model mm with (nolock)
								on t.ModelCode = mm.ModelCode
						where (1=1)
							zzzzClauseWhereSpecCodeList
							zzzzClauseWhereSpecCodePattern
							zzzzClauseWhereModelCodeList
							zzzzClauseWhereStandardCodeList
							zzzzClauseWhereAdvancedCodeList
							zzzzClauseWhereFlagActiveListForModel
							;
					";
				string zzzzClauseWhereSpecCodeList = SqlUtils.BuildClauseConditionList("and", "t.SpecCode", strSpecCodeList, "|");
				string zzzzClauseWhereSpecCodePattern = SqlUtils.BuildClauseConditionSingle("and", "t.SpecCode", "like", "@strSpecCodePattern", strSpecCodePattern, ref alParamsCoupleSql);
				string zzzzClauseWhereModelCodeList = SqlUtils.BuildClauseConditionList("and", "t.ModelCode", strModelCodeList, "|");
				string zzzzClauseWhereStandardCodeList = SqlUtils.BuildClauseConditionList("and", "t.StandardCode", strStandardCodeList, "|");
				string zzzzClauseWhereAdvancedCodeList = SqlUtils.BuildClauseConditionList("and", "t.AdvancedCode", strAdvancedCodeList, "|");
				string zzzzClauseWhereFlagActiveListForModel = SqlUtils.BuildClauseConditionList("and", "mm.FlagActive", strFlagActiveListForModel, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereSpecCodeList", zzzzClauseWhereSpecCodeList
					, "zzzzClauseWhereSpecCodePattern", zzzzClauseWhereSpecCodePattern
					, "zzzzClauseWhereModelCodeList", zzzzClauseWhereModelCodeList
					, "zzzzClauseWhereStandardCodeList", zzzzClauseWhereStandardCodeList
					, "zzzzClauseWhereAdvancedCodeList", zzzzClauseWhereAdvancedCodeList
					, "zzzzClauseWhereFlagActiveListForModel", zzzzClauseWhereFlagActiveListForModel
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _db.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Mst_ModelAdvancedOption";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet MstDataGetModelStandardOption(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strModelCodeList
			, string strStandardCodeList
			, string strFlagActiveListForModel
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "MstDataGetModelStandardOption";
			string strErrorCodeDefault = TError.ErrHTC.MstDataGetModelStandardOption;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strModelCodeList", strModelCodeList
					, "strStandardCodeList", strStandardCodeList
					, "strFlagActiveListForModel", strFlagActiveListForModel
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.ModelCode
							, t.StandardCode
							, t.StdDescription
							, mm.ModelProductionCode
							, mm.ModelName
							, mm.FlagActive MMFlagActive
						from Mst_ModelStandardOption t with (nolock)
							inner join Mst_Model mm with (nolock)
								on t.ModelCode = mm.ModelCode
						where (1=1)
							zzzzClauseWhereModelCodeList
							zzzzClauseWhereStandardCodeList
							zzzzClauseWhereFlagActiveListForModel
							;
					";
				string zzzzClauseWhereModelCodeList = SqlUtils.BuildClauseConditionList("and", "t.ModelCode", strModelCodeList, "|");
				string zzzzClauseWhereStandardCodeList = SqlUtils.BuildClauseConditionList("and", "t.StandardCode", strStandardCodeList, "|");
				string zzzzClauseWhereFlagActiveListForModel = SqlUtils.BuildClauseConditionList("and", "mm.FlagActive", strFlagActiveListForModel, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereModelCodeList", zzzzClauseWhereModelCodeList
					, "zzzzClauseWhereStandardCodeList", zzzzClauseWhereStandardCodeList
					, "zzzzClauseWhereFlagActiveListForModel", zzzzClauseWhereFlagActiveListForModel
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _db.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Mst_ModelStandardOption";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet MstDataGetModel(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strModelCodeList
			, string strModelProductionCodeList
			, string strModelNamePattern
			, string strFlagActiveList
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "MstDataGetModel";
			string strErrorCodeDefault = TError.ErrHTC.MstDataGetModel;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strModelCodeList", strModelCodeList
					, "strModelProductionCodeList", strModelProductionCodeList
					, "strModelNamePattern", strModelNamePattern
					, "strFlagActiveList", strFlagActiveList
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.*
						from Mst_Model t with (nolock)
						where (1=1)
							zzzzClauseWhereModelCodeList
							zzzzClauseWhereModelProductionCodeList
							zzzzClauseWhereModelNamePattern
							zzzzClauseWhereFlagActiveList
						;
					";
				string zzzzClauseWhereModelCodeList = SqlUtils.BuildClauseConditionList("and", "t.ModelCode", strModelCodeList, "|");
				string zzzzClauseWhereModelProductionCodeList = SqlUtils.BuildClauseConditionList("and", "t.ModelProductionCode", strModelProductionCodeList, "|");
				string zzzzClauseWhereModelNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.ModelName", "like", "@strModelNamePattern", strModelNamePattern, ref alParamsCoupleError);
				string zzzzClauseWhereFlagActiveList = SqlUtils.BuildClauseConditionList("and", "t.FlagActive", strFlagActiveList, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereModelCodeList", zzzzClauseWhereModelCodeList
					, "zzzzClauseWhereModelProductionCodeList", zzzzClauseWhereModelProductionCodeList
					, "zzzzClauseWhereModelNamePattern", zzzzClauseWhereModelNamePattern
					, "zzzzClauseWhereFlagActiveList", zzzzClauseWhereFlagActiveList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _db.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Mst_Model";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet MstDataGetDealer(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strDealerCodeList
			, string strDealerTypeList
			, string strAreaCodeList
			, string strBUCodeList
			, string strBUCodePattern
			, string strDealerNamePattern
			, string strFlagActiveList
			, string strTaxCodeList
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "MstDataGetDealer";
			string strErrorCodeDefault = TError.ErrHTC.MstDataGetDealer;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strDealerCodeList", strDealerCodeList
					, "strDealerTypeList", strDealerTypeList
					, "strAreaCodeList", strAreaCodeList
					, "strBUCodeList", strBUCodeList
					, "strBUCodePattern", strBUCodePattern
					, "strDealerNamePattern", strDealerNamePattern
					, "strFlagActiveList", strFlagActiveList
					, "strTaxCodeList", strTaxCodeList
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.*
							, ma.AreaName
						from Mst_Dealer t with (nolock)
							inner join Mst_Area ma with (nolock)
								on t.AreaCode = ma.AreaCode
						where (1=1)
							zzzzClauseWhere_strDealerCodeList
							zzzzClauseWhere_strDealerTypeList
							zzzzClauseWhere_strAreaCodeList
							zzzzClauseWhere_strBUCodeList
							zzzzClauseWhere_strBUCodePattern
							zzzzClauseWhere_strDealerNamePattern
							zzzzClauseWhere_strFlagActiveList
							zzzzClauseWhere_strTaxCodeList
						;
					";

				string zzzzClauseWhere_strDealerCodeList = SqlUtils.BuildClauseConditionList("and", "t.DealerCode", strDealerCodeList, "|");
				string zzzzClauseWhere_strDealerTypeList = SqlUtils.BuildClauseConditionList("and", "t.DealerType", strDealerTypeList, "|");
				string zzzzClauseWhere_strAreaCodeList = SqlUtils.BuildClauseConditionList("and", "t.AreaCode", strAreaCodeList, "|");
				string zzzzClauseWhere_strBUCodeList = SqlUtils.BuildClauseConditionList("and", "t.BUCode", strBUCodeList, "|");
				string zzzzClauseWhere_strBUCodePattern = SqlUtils.BuildClauseConditionSingle("and", "t.BUCode", "like", "@strBUCodePattern", strBUCodePattern, ref alParamsCoupleSql);
				string zzzzClauseWhere_strDealerNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.DealerName", "like", "@strDealerNamePattern", strDealerNamePattern, ref alParamsCoupleSql);
				string zzzzClauseWhere_strFlagActiveList = SqlUtils.BuildClauseConditionList("and", "t.FlagActive", strFlagActiveList, "|");
				string zzzzClauseWhere_strTaxCodeList = SqlUtils.BuildClauseConditionList("and", "t.TaxCode", strTaxCodeList, "|");

				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhere_strDealerCodeList", zzzzClauseWhere_strDealerCodeList
					, "zzzzClauseWhere_strDealerTypeList", zzzzClauseWhere_strDealerTypeList
					, "zzzzClauseWhere_strAreaCodeList", zzzzClauseWhere_strAreaCodeList
					, "zzzzClauseWhere_strBUCodeList", zzzzClauseWhere_strBUCodeList
					, "zzzzClauseWhere_strBUCodePattern", zzzzClauseWhere_strBUCodePattern
					, "zzzzClauseWhere_strDealerNamePattern", zzzzClauseWhere_strDealerNamePattern
					, "zzzzClauseWhere_strFlagActiveList", zzzzClauseWhere_strFlagActiveList
					, "zzzzClauseWhere_strTaxCodeList", zzzzClauseWhere_strTaxCodeList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _db.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Mst_Dealer";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet MstDataGetColor(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strColorCodeList
			, string strModelCodeList
			, string strFlagActiveListForModel
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "MstDataGetColor";
			string strErrorCodeDefault = TError.ErrHTC.MstDataGetColor;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strColorCodeList", strColorCodeList
					, "strModelCodeList", strModelCodeList
					, "strFlagActiveListForModel", strFlagActiveListForModel
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.ModelCode
							, t.ColorCode
							, t.ColorExtType
							, t.ColorExtCode
							, t.ColorExtName
							, t.ColorExtNameVN
							, t.ColorIntName
							, t.ColorIntNameVN
							, t.ColorFee
							, t.Remark
							, mm.ModelProductionCode
							, mm.ModelName
							, mm.FlagActive MMFlagActive
						from Mst_Color t with (nolock)
							inner join Mst_Model mm with (nolock)
								on t.ModelCode = mm.ModelCode
						where (1=1)
							zzzzClauseWhereColorCodeList
							zzzzClauseWhereModelCodeList
							zzzzClauseWhereFlagActiveListForModel
						;
					";
				string zzzzClauseWhereColorCodeList = SqlUtils.BuildClauseConditionList("and", "t.ColorCode", strColorCodeList, "|");
				string zzzzClauseWhereModelCodeList = SqlUtils.BuildClauseConditionList("and", "t.ModelCode", strModelCodeList, "|");
				string zzzzClauseWhereFlagActiveListForModel = SqlUtils.BuildClauseConditionList("and", "mm.FlagActive", strFlagActiveListForModel, "|");

				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereColorCodeList", zzzzClauseWhereColorCodeList
					, "zzzzClauseWhereModelCodeList", zzzzClauseWhereModelCodeList
					, "zzzzClauseWhereFlagActiveListForModel", zzzzClauseWhereFlagActiveListForModel
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _db.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Mst_Color";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet MstDataGetPort(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strPortCodeList
			, string strPortNamePattern
			, string strPortTypeList
			, string strAreaCodeList
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "MstDataGetPort";
			string strErrorCodeDefault = TError.ErrHTC.MstDataGetPort;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strPortCodeList", strPortCodeList
					, "strPortNamePattern", strPortNamePattern
					, "strPortTypeList", strPortTypeList
					, "strAreaCodeList", strAreaCodeList
					});
			#endregion

			try
			{
				#region // Init:
				_db.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _db.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.PortCode
							, t.PortName
							, t.Address
							, t.PortType
							, t.AreaCode
						from Mst_Port t with (nolock)
							inner join Mst_PortType mpt with (nolock)
								on t.PortType = mpt.PortType
							inner join Mst_Area ma with (nolock)
								on t.AreaCode = ma.AreaCode
						where (1=1)
							zzzzClauseWherePortCodeList
							zzzzClauseWherePortNamePattern
							zzzzClauseWherePortTypeList
							zzzzClauseWhereAreaCodeList
						;
					";
				string zzzzClauseWherePortCodeList = SqlUtils.BuildClauseConditionList("and", "t.PortCode", strPortCodeList, "|");
				string zzzzClauseWherePortNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.PortName", "like", "@strPortNamePattern", strPortNamePattern, ref alParamsCoupleSql);
				string zzzzClauseWherePortTypeList = SqlUtils.BuildClauseConditionList("and", "t.PortType", strPortCodeList, "|");
				string zzzzClauseWhereAreaCodeList = SqlUtils.BuildClauseConditionList("and", "t.AreaCode", strAreaCodeList, "|");

				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWherePortCodeList", zzzzClauseWherePortCodeList
					, "zzzzClauseWherePortNamePattern", zzzzClauseWherePortNamePattern
					, "zzzzClauseWherePortTypeList", zzzzClauseWherePortTypeList
					, "zzzzClauseWhereAreaCodeList", zzzzClauseWhereAreaCodeList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _db.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Mst_Port";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_db);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_db);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_db);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_db_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		#endregion

	}
}
